package softtech.apps.dangtinraovat;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import softtech.apps.adapter.UserListAdapter;
import softtech.apps.model.Conversation;
import softtech.apps.model.DatabaseHandler;
import softtech.apps.model.User;
import softtech.apps.utilities.HttpRequest;
import softtech.apps.utilities.Utilities;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

public class ActivityUserList extends Activity {
	
	private static final String TAG = "ActivityUserList";

    private UserListAdapter userListAdapter;
	private ListView listView;
	private static int colorIndex;
	private DatabaseHandler dbHandler;
	List<User> userList;
	Button btSyncUser;
	String regId;
	public ActivityUserList() {
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.userlist);
		
		 Intent i = getIntent();
		 regId = i.getStringExtra("regId");
		// Init all varialable value
        colorIndex = 0;
        dbHandler = new DatabaseHandler(getApplicationContext());
        
        // Init all view
		listView = (ListView) findViewById(R.id.listView);
		btSyncUser = (Button) findViewById(R.id.btSyncUser);
		
		userListAdapter = new UserListAdapter(getApplicationContext(),userList);
		listView.setAdapter(userListAdapter);
        listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getApplicationContext(),
		                ActivityConversation.class);
				int touserid = userListAdapter.getItem(position).getId_server();
		        i.putExtra("touserid",touserid);
		        startActivity(i);
		        finish();
			}
		});
       
	}
}
